<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>结算页</title>
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
	<link rel="stylesheet" type="text/css" href="./css/order.css" />
</head>

<body>
    <!--head-->
    <!-- 头部栏位 -->
    <!--页面顶部-->
    <div id="nav-bottom">
        <!--顶部-->
        <div class="nav-top">
            <div class="top">
                <div class="py-container">
                    <div class="shortcut">
                        <ul class="fl">
                            <li class="f-item">shop欢迎您！</li>
                            <li class="f-item">请<a href="login.html" target="_blank">登录</a>　<span><a href="register.html" target="_blank">免费注册</a></span></li>
                        </ul>
                        <div class="fr typelist">
                            <ul class="types">
                                <li class="f-item"><span>我的订单</span></li>

                                <li class="f-item"><span><a href="cart.html" target="_blank">我的购物车</a></span></li>
                                <li class="f-item"><span><a href="home.html" target="_blank">我的shop</a></span></li>
                                <li class="f-item"><span>shop会员</span></li>
                                <li class="f-item"><span>企业采购</span></li>
                                <li class="f-item"><span>关注shop</span></li>
                                <li class="f-item"><span><a href="cooperation.html" target="_blank">合作招商</a></span></li>
                                <li class="f-item"><span><a href="shoplogin.html" target="_blank">商家后台</a></span></li>
                                <li class="f-item"><span>网站导航</li>
						</ul>
					</div>
					
				</div>
			</div>
		</div>

		<!--头部-->
		<div class="header">
			<div class="py-container">
				<div class="yui3-g Logo">
					<div class="yui3-u Left logoArea">
						<a class="logo-bd" title="shop" href="index.html" target="_blank"></a>
					</div>
					<div class="yui3-u Rit searchArea">
						<div class="search">
							<form action="" class="sui-form form-inline">
								<!--searchAutoComplete-->
								<div class="input-append">
									<input type="text" id="autocomplete" class="input-error input-xxlarge" />
									<button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
								</div>
							</form>
						</div>
					</div>
					
				</div>

			</div>
		</div>
	</div>
</div>


	<div class="cart py-container" id="app">
		<!--主内容-->
		<div class="checkout py-container">
			<div class="checkout-tit">
				<h4 class="tit-txt">填写并核对订单信息</h4>
			</div>
			<div class="checkout-steps">
				<!--收件人信息-->
				<div class="step-tit">
					<h5>收件人信息<span></span></h5>
                        </div>
                        <div class="step-cont">
                            <div class="addressInfo">
                                <ul class="addr-detail">
                                    <li class="addr-item">
                                        <div class="choose-address" v-for="(item,index) in addressList" :key="index">
                                            <div @click="address=item" :class="['con','name',item.isDefault===1? 'selected':'']"><a href="javascript:;">{{item.contact}}<span title="点击取消选择"></span></a></div>
                                            <div class="con address">
                                                <span class="place">{{item.address}}</span>
                                                <span class="phone">{{item.phone}}<span v-if="item.isDefault===1">【默认】</span></span>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>
                                    </li>
                                </ul>
                                <!--确认地址-->
                            </div>
                        </div>
                        <div class="hr"></div>
                        <!--支付和送货-->
                        <div class="payshipInfo">
                            <div class="step-tit">
                                <h5>支付方式</h5>
                            </div>
                            <div class="step-cont">
                                <ul class="payType">
                                    <li @click="order.payType=1">支付宝<span title="点击取消选择"></span></li>
                                    <li class="selected" @click="order.payType=2">微信<span title="点击取消选择"></span></li>
                                </ul>
                            </div>
                            <div class="hr"></div>
                            <div class="step-tit">
                                <h5>送货清单</h5>
                            </div>
                            <div class="step-cont">
                                <ul class="send-detail">
                                    <li>
                                        <div class="sendGoods">
                                            <span>商品清单：</span>
                                            <ul class="yui3-g" v-for="(cart,index) in carts" :key="index">
                                                <li class="yui3-u-1-6">
                                                    <span><img :src="cart.image" style="max-height: 100px;"/></span>
                                                </li>
                                                <li class="yui3-u-7-12">
                                                    <div class="desc">{{cart.name}}</div>
                                                    <div class="seven">7天无理由退货</div>
                                                </li>
                                                <li class="yui3-u-1-12">
                                                    <div class="price">￥{{cart.price}}</div>
                                                </li>
                                                <li class="yui3-u-1-12">
                                                    <div class="num">X{{cart.num}}</div>
                                                </li>
                                                <li class="yui3-u-1-12">
                                                    <div class="exit">有货</div>
                                                </li>
                                            </ul>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix trade">
                    <div class="fc-price">应付金额:　<span class="price">¥{{allMoney()}}</span></div>
                    <div class="fc-receiverInfo">
                        寄送至:
                        <span id="receive-address">江苏省苏州市**********</span> 收货人：
                        <span id="receive-name">John</span>
                        <span id="receive-phone">137718XXXX</span>
                    </div>
                </div>
                <div class="submit">
                    <a class="sui-btn btn-danger btn-xlarge" @click="addOrder()">提交订单</a>
                </div>
            </div>
            <!-- 底部栏位 -->
            <!--页面底部-->
            <div class="clearfix footer">
                <div class="py-container">
                    <div class="footlink">
                        <div class="Mod-service">
                            <ul class="Mod-Service-list">
                                <li class="grid-service-item intro  intro1">

                                    <i class="serivce-item fl"></i>
                                    <div class="service-text">
                                        <h4>正品保障</h4>
                                        <p>正品保障，提供发票</p>
                                    </div>

                                </li>
                                <li class="grid-service-item  intro intro2">

                                    <i class="serivce-item fl"></i>
                                    <div class="service-text">
                                        <h4>正品保障</h4>
                                        <p>正品保障，提供发票</p>
                                    </div>

                                </li>
                                <li class="grid-service-item intro  intro3">

                                    <i class="serivce-item fl"></i>
                                    <div class="service-text">
                                        <h4>正品保障</h4>
                                        <p>正品保障，提供发票</p>
                                    </div>

                                </li>
                                <li class="grid-service-item  intro intro4">

                                    <i class="serivce-item fl"></i>
                                    <div class="service-text">
                                        <h4>正品保障</h4>
                                        <p>正品保障，提供发票</p>
                                    </div>

                                </li>
                                <li class="grid-service-item intro intro5">

                                    <i class="serivce-item fl"></i>
                                    <div class="service-text">
                                        <h4>正品保障</h4>
                                        <p>正品保障，提供发票</p>
                                    </div>

                                </li>
                            </ul>
                        </div>
                        <div class="clearfix Mod-list">
                            <div class="yui3-g">
                                <div class="yui3-u-1-6">
                                    <h4>购物指南</h4>
                                    <ul class="unstyled">
                                        <li>购物流程</li>
                                        <li>会员介绍</li>
                                        <li>生活旅行/团购</li>
                                        <li>常见问题</li>
                                        <li>购物指南</li>
                                    </ul>

                                </div>
                                <div class="yui3-u-1-6">
                                    <h4>配送方式</h4>
                                    <ul class="unstyled">
                                        <li>上门自提</li>
                                        <li>211限时达</li>
                                        <li>配送服务查询</li>
                                        <li>配送费收取标准</li>
                                        <li>海外配送</li>
                                    </ul>
                                </div>
                                <div class="yui3-u-1-6">
                                    <h4>支付方式</h4>
                                    <ul class="unstyled">
                                        <li>货到付款</li>
                                        <li>在线支付</li>
                                        <li>分期付款</li>
                                        <li>邮局汇款</li>
                                        <li>公司转账</li>
                                    </ul>
                                </div>
                                <div class="yui3-u-1-6">
                                    <h4>售后服务</h4>
                                    <ul class="unstyled">
                                        <li>售后政策</li>
                                        <li>价格保护</li>
                                        <li>退款说明</li>
                                        <li>返修/退换货</li>
                                        <li>取消订单</li>
                                    </ul>
                                </div>
                                <div class="yui3-u-1-6">
                                    <h4>特色服务</h4>
                                    <ul class="unstyled">
                                        <li>夺宝岛</li>
                                        <li>DIY装机</li>
                                        <li>延保服务</li>
                                        <li>购物卡</li>
                                        <li>会员充值卡</li>
                                    </ul>
                                </div>
                                <div class="yui3-u-1-6">
                                    <h4>帮助中心</h4>
                                    <ul class="unstyled">
                                        <li>夺宝岛</li>
                                        <li>DIY装机</li>
                                        <li>延保服务</li>
                                        <li>购物卡</li>
                                        <li>会员充值卡</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="Mod-copyright">
                            <ul class="helpLink">
                                <li>关于我们<span class="space"></span></li>
                                <li>联系我们<span class="space"></span></li>
                                <li>关于我们<span class="space"></span></li>
                                <li>商家入驻<span class="space"></span></li>
                                <li>营销中心<span class="space"></span></li>
                                <li>友情链接<span class="space"></span></li>
                                <li>关于我们<span class="space"></span></li>
                                <li>营销中心<span class="space"></span></li>
                                <li>友情链接<span class="space"></span></li>
                                <li>关于我们</li>
                            </ul>
                            <p>Copyright©2017-2021 All Rights Reserved.</p>
                        </div>
                    </div>
                </div>
            </div>
            <!--页面底部END-->
            <script type="text/javascript" src="js/jquery/jquery.min.js"></script>
			<!-- 引入组件库 -->
			<script src="js/vue.js"></script>
			<script src="js/axios.js"></script>
            <script>
				var app = new Vue({
					el:'#app',
					data(){
						return {
							//收件地址列表
							addressList:[
								{
									address: "湖南省长沙市岳麓区芯城科技园二期",
									contact: "Tom",
									isDefault: 1,
									phone: "15632223336"
								},
								{
									address: "湖南省长沙市岳麓区芯城科技园二期",
									contact: "微微",
									isDefault: 0,
									phone: "16552233354"
								},
								{
									address: "湖南省长沙市岳麓区芯城科技园二期",
									contact: "云帆",
									isDefault: 0,
									phone: "16956665588"
								}
							],
							//选中收件地址
							address:{},
							//购物车列表
							carts: [{
								name: '科尔沁 休闲肉脯零食 中秋礼品 内蒙古特产 手撕风干牛肉干原味400g',
								price: '125.00',
								num:1,
								image:'./img/can12.jpg',
								skuId:'No001'
							}, {
								name: '科尔沁 休闲肉脯零食 中秋礼品 内蒙古特产 手撕风干牛肉干原味400g',
								price: '125.00',
								num:1,
								image:'./img/can12.jpg',
								skuId:'No002'
							}, {
								name: '科尔沁 休闲肉脯零食 中秋礼品 内蒙古特产 手撕风干牛肉干原味400g',
								price: '125.00',
								num:1,
								image:'./img/can12.jpg',
								skuId:'No003'
							}],
							//订单对象
							order:{
								payType:1,	//1支付宝,2微信
								recipients:null,//收件人
								recipientsMobile:null,
								recipientsAddress:null,
								cartIds:[]
							}
						}
					},
					created() {
						this.loadAddress()
						this.list()
					},
					methods:{
						//下单
						addOrder(){
							this.order.recipients=this.address.contact
							this.order.recipientsMobile=this.address.phone
							this.order.recipientsAddress=this.address.address
							//添加订单
							axios.post('http://localhost:8089/order',this.order).then(function(resp){
								alert(resp.data.message)
								//跳转到支付页面,并且携带加密字符
								if(resp.data.code===20000){
									location.href="pay.html?ciptext="+encodeURI(resp.data.data).replace(/\+/g,'%2B');
								}
							})
						},
						
						//用户地址加载
						loadAddress(){
							axios.get('http://localhost:8088/address/list').then(function(resp){
								app.addressList=resp.data.data;
								for(var i=0;i<app.addressList.length;i++){
									if(app.addressList[i].isDefault===1){
										app.address=app.addressList[i]
									}
								}
							})
						},
						//购物车列表加载
						list(){
							let ids = this.getQueryString('ids').split(",")
							this.order.cartIds=ids;
							axios.post('http://localhost:8087/cart/list',ids).then(function(resp){
								app.carts=resp.data.data;
							})
						},
						//获取地址栏参数
						getQueryString(name){
							 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
							 var r = window.location.search.substr(1).match(reg);
							 if(r!=null)return  decodeURI(r[2]); return null;
						},
						//总金额计算
						allMoney(){
							let moneys = 0.0;
							for(var i=0;i<this.carts.length;i++){
								moneys+=this.carts[i].num*this.carts[i].price
							}
							return moneys;
						}
					}
				})
				
                $(function() {
                    $(".address").hover(function() {
                        $(this).addClass("address-hover");
                    }, function() {
                        $(this).removeClass("address-hover");
                    });

                    $(".choose-address .name").click(function() {
                        $(this).addClass("selected");
                        $(this).parent().siblings().children('.name').removeClass("selected");
                        var place = $(this).siblings('.address').children('.place').text();
                        var phone = $(this).siblings('.address').children('.phone').text();
                        $("#receive-name").text($(this).text());
                        $("#receive-address").text(place);
                        $("#receive-phone").text(phone)
                    });
                    $(".payType li").click(function() {
                        $(this).toggleClass("selected").siblings().removeClass("selected");
                    });
                })
            </script>

</body>

</html>